    // MainWnd.h : interface of the MainWnd class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

#include <atlwince.h>
#include <atlcrack.h>

#include <memory>

#include "resource.h"
#include "MainWndMode.h"
#include "Options.h"
#include "ListView.h"
#include "MemoView.h"
#include "Executor.h"

class ListModel;

class MainWnd : public CFrameWindowImpl<MainWnd>
                 , public CUpdateUI<MainWnd>
                 , public CMessageFilter
                 , public CAppWindow<MainWnd>
                 , public CIdleHandler
{
public:

    typedef CFrameWindowImpl<MainWnd> _parentType;

    MainWnd();
    ~MainWnd();

	DECLARE_APP_FRAME_CLASS(NULL, IDR_MAINFRAME, L"Software\\pm")

	virtual BOOL PreTranslateMessage(MSG* pMsg);
	virtual BOOL OnIdle();

	BEGIN_UPDATE_UI_MAP(MainWnd)
	END_UPDATE_UI_MAP()

    MainWndMode *CurrentMode;

	BEGIN_MSG_MAP_EX(MainWnd)

        MESSAGE_HANDLER(WM_CREATE, OnCreate)
        MSG_WM_CLOSE(OnClose)

        MESSAGE_HANDLER(WM_CONTEXTMENU, OnContextMenu)
        COMMAND_ID_HANDLER(ID_APP_EXIT, OnFileExit)
        COMMAND_ID_HANDLER(ID_LIST_DELETE, OnFileDelete)
		COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
        COMMAND_ID_HANDLER(ID_APP_OPTIONS, OnOptions)
        CHAIN_MSG_MAP(CUpdateUI<MainWnd>)
		CHAIN_MSG_MAP(CFrameWindowImpl<MainWnd>)
        CHAIN_MSG_MAP(CAppWindow<MainWnd>)

        {
            if ( CurrentMode != NULL ) {
                if( CurrentMode->ProcessWindowMessage(hWnd, uMsg, wParam, lParam, lResult) )
                    return TRUE;
            }
        }

	END_MSG_MAP()

	BOOL CreateSimpleCEMenuBar(UINT nToolBarId = 0, DWORD dwFlags = 0, int nBmpId = 0, int cBmpImages = 0);
    void GetClientRect( CRect *rect );

	LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);

    void OnClose();

	LRESULT OnContextMenu(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);

	LRESULT OnPopMenu(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnOptions(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnFileDelete(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

    void OpenItem(int item);

    std::auto_ptr<Executor> executor;
    std::auto_ptr<Options> options;

    // list view state
    ListModel listModel;
    ListView listView;

    // edit memo state
    MemoView memoView;
};